package com.njust.controller;

import com.njust.Util.ExcelUtil;
import com.njust.domain.dto.*;
import com.njust.domain.vo.TestPageQueryPersonVO;
import com.njust.domain.vo.TestPageQueryVO;
import com.njust.result.Result;
import com.njust.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/test")
@Slf4j
public class TestController {
    @Autowired
    private TestService testService;
    @Autowired
    private ExcelUtil excelUtil;
    
    @PostMapping("/upload")
    public Result<String> upload(@RequestBody TestUploadDTO testUploadDTO) {
        log.info("上传比对方案: {}", testUploadDTO);
        testService.upload(testUploadDTO);
        return Result.success("上传比对方案成功");
    }
    
    @PostMapping("/joinInTest")
    public Result<String> joinInTest(@RequestBody TestJoinDTO testJoinDTO) {
        log.info("申请参加比对测试: {}",testJoinDTO);
        testService.joinInTest(testJoinDTO);
        return Result.success("申请参加比对测试成功");
    }
    @GetMapping("/pageQuery")
    public Result<TestPageQueryVO> pageQuery(TestPageQueryDTO testPageQueryDTO) {
        log.info("分页查询申请比对测试清单: {}", testPageQueryDTO);
        TestPageQueryVO testPageQueryVO = testService.pageQuery(testPageQueryDTO);
        return Result.success(testPageQueryVO, "分页查询申请比对测试清单成功");
    }
    @PostMapping("/status/{status}")
    public Result<String> update(@PathVariable int status, @RequestBody TestUpdateDTO testUpdateDTO) {
        log.info("进入修改比对测试状态: {}",testUpdateDTO);
        testService.update(status, testUpdateDTO);
        return Result.success("修改比对测试状态成功");
    }
    @GetMapping("/export_test/{project_id}")
    public Result<String> export_test(HttpServletResponse response, @PathVariable int project_id) {
        log.info("导出比对测试申请清单:{}", project_id);
        excelUtil.exportTestExcel(response,project_id);
        return Result.success("导出比对测试清单成功");
    }
}
